import copy
# 创建字典
# 直接赋值
dict_01 = {"a":"2001",'b':['2002','22003'],'c':{'d':1}}
# print(dict_01)

# # 函数dict()创建
dict_02 = dict(dict_01)
# print(dict_02)
dict_03 = dict([('a','111'),('b','222'),('c','333')])
# print(dict_03)
dict_04 = dict(a = "123",b = "456",c = "789")
# print(dict_04)
dict_05 = dict(zip(['a','b','c'],['1','2','3']))
# print(dict_05)

# fromkeys()
dict_06 = dict.fromkeys(['a','b','c'])
# print(dict_06)
dict_07 = dict.fromkeys(['a','b','c'],1)
# print(dict_07)

dict_08 = {'a':1,'b':2,'c':3,'d':4,'a':5}
# print(dict_08)

# 字典的访问
# 通过键访问
# print(dict_04['b'])
# print(dict_04.get('a'))
# print(dict_04.get('e'))
# print(dict_04.get('e','111'))

# 字典的常用操作
# 修改和添加
# dict_08['e'] = 6
# dict_08['c'] = 6
# print(dict_08)

# 删除元素
# del dict_08['a']
# print(dict_08)
# dict_08.clear()
# print(dict_08)
# item = dict_08.pop('a',1)
# # item_01 = dict_08.pop('a')  # 会报错，不能这样写
# print(item)
# # print(item_01)
# print(dict_08)
# print(dict_04.popitem())
# print(dict_04)

# 更新字典
print(dict_08)
# dict_08.update(dict_04)
# print(dict_08)

# 复制字典
dict_09 = dict_08.copy()
# print(dict_09)
# print(dict_04)
dict_10 = dict_04
# print(dict_10)
dict_11 = copy.deepcopy(dict_04)
# print(dict_11)

# 字典遍历
# print(dict_02.items())
# print(dict_03.keys())
# print(dict_04.values())